//
//  TopicDetailsTableViewCell.m
//  XiangMuB
//
//  Created by 向修根 on 16/8/13.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "TopicDetailsTableViewCell.h"
#import "TopicDetailsModel.h"
#import "NSDate+Extention.h"
#import <UIImageView+WebCache.h>


@implementation TopicDetailsTableViewCell

- (void)layoutSubviews{
    [super layoutSubviews];
    self.content.text = self.model.content;
    self.userName.text = self.model.userName;
    [self.userHeadPicUrl sd_setImageWithURL:[NSURL URLWithString:self.model.userHeadPicUrl] placeholderImage:nil];
    NSString *str = [NSString stringWithFormat:@"%@",self.model.supportCount];
    self.supportCount.text = str;
    
    NSString *str1 = [NSString stringWithFormat:@"%@",self.model.discussCount];
    self.discussCount.text = str1;
    NSString *str2 = [NSString stringWithFormat:@"%@",self.model.cTime];
    NSLog(@"%@",str2);
    //    弧度
    self.cellView.layer.cornerRadius = self.cellView.frame.size.width /50;
    self.cellView.layer.masksToBounds = YES;
    //   cell边框
    self.cellView.layer.borderWidth = 2;
    self.cellView.layer.borderColor = [[UIColor colorWithRed:192.0f/255.0f  green:192.0f/255.0f  blue:192.0f/255.0f  alpha:0.7]CGColor];
    
    //时间戳赋值

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"YYYY-MM-dd HH:mm:ss";
    NSInteger timeint = [str2 intValue];
    NSDate *creat = [NSDate dateWithTimeIntervalSince1970:timeint/1000];
    NSString *datestr2 = [formatter stringFromDate:creat];
    NSLog(@"%@",creat);
    
    if (creat.isThisYear) {//今年
        if (creat.isToday) {//今天
            NSDateComponents *cmps = [[NSDate date] deltaFrom:creat];
        
            
            if (cmps.hour >= 1) {//大于1小时
                self.cTimeLabel.text = [NSString stringWithFormat:@"%zd小时前",cmps.hour];
            }else if (cmps.minute >= 1){//大于1分钟
                self.cTimeLabel.text = [NSString stringWithFormat:@"%zd分钟前",cmps.minute];
            }else{//小于1分钟
                self.cTimeLabel.text = @"刚刚";
            }
        } else if (creat.isYesterday){//昨天
            formatter.dateFormat = @"昨天 HH:mm:ss";
            self.cTimeLabel.text = [formatter stringFromDate:creat];
        }else{//其他
            formatter.dateFormat = @"MM-dd HH:mm:ss";
            self.cTimeLabel.text = [formatter stringFromDate:creat];
        }
    } else {//非今年
        self.cTimeLabel.text = datestr2;
        
    }
    
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
